/**
 *  *  This file is part of Spidex.
 *  
 *  Spidex is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  Spidex is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Spidex.  If not, see <http://www.gnu.org/licenses/>.
 */
package spidex;

import java.util.HashSet;
import java.util.Set;


import javax.swing.ImageIcon;
public class FilmInfo implements FilmInfoInterface {

    private ImageIcon poster;
    private String title;
    private Set<String> directors = new HashSet<String>();
    private Set<String> actors = new HashSet<String>();
    private String genre;
    private String filmUrl;
    private String posterUrl;
    private int yearOfRelease;
    private int length;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.8A67E332-A810-7938-322F-24E1E895CB0A]
    // </editor-fold> 
    public FilmInfo () {
        this.poster = new ImageIcon(
            getClass().getResource("/spidex/resources/not_avail.jpg")
        );
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.DD125A99-245A-BAA7-85AA-37006A6E2548]
    // </editor-fold> 
    public Set<String> getActors () {
        return actors;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.EFE99C1E-A2F0-0982-1E29-D976A47DC1BA]
    // </editor-fold> 
    public void addActor(String actor) {
        if(actor == null) {
            throw new NullPointerException("director");
        }
        this.actors.add(actor);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.27E76ABE-1CA7-D7B8-7485-F35D967A1884]
    // </editor-fold> 
    public Set<String> getDirectors () {
        return directors;
    }

    public void addDirector(String director) {
        if(director == null) {
            throw new NullPointerException("director");
        }
        this.directors.add(director);
    }
    
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.83EE756F-0DCD-8D6B-B5DE-75E48324C3C8]
    // </editor-fold> 
    public String getGenre () {
        return genre;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.CAC2E7A4-DE05-D02E-AF02-5532655B95DB]
    // </editor-fold> 
    public void setGenre (String val) {
        this.genre = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.EB40CA74-E6D4-5341-B515-EF83809E13FF]
    // </editor-fold> 
    public int getLength () {
        return length;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.27E5AEA2-1D49-C3D0-DB51-1407646686BA]
    // </editor-fold> 
    public void setLength (int val) {
        this.length = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.A2701C81-6C62-395E-A975-5B38ADA40358]
    // </editor-fold> 
    public String getTitle () {
        return title;
    }

    public void setPoster(ImageIcon icon) {
        this.poster = icon;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.8556FB57-01D2-463E-6B0F-5FFC47A706D8]
    // </editor-fold> 
    public void setTitle (String val) {
        this.title = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.88FCF856-6EF9-D45D-B642-D4C3EC469827]
    // </editor-fold> 
    public int getYearOfRelease () {
        return yearOfRelease;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.0C5000CC-5A1D-96D7-66CC-419B7AD6B93E]
    // </editor-fold> 
    public void setYearOfRelease (int val) {
        this.yearOfRelease = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.7B9C0C76-76C8-2802-CF7B-6F923FF4AF30]
    // </editor-fold> 
    public ImageIcon getPoster () {
        return poster;
    }
    
        public String getFilmUrl() {
        return filmUrl;
    }

    public void setFilmUrl(String filmUrl) {
        this.filmUrl = filmUrl;
    }

    public String getPosterUrl() {
        return posterUrl;
    }

    public void setPosterUrl(String posterUrl) {
        this.posterUrl = posterUrl;
    }

    @Override
    public String toString() {
        return this.getTitle()+"|"+this.getGenre()+"|"
            +this.getDirectors()+"|"+this.getActors();
    }
    
        @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FilmInfo other = (FilmInfo) obj;
        if (this.title == null || this.filmUrl == null ) {
            return false;
        }
        if( !this.title.equals( other.getTitle() ) ) {
            return false;
        }
        if( !this.filmUrl.equals( other.getFilmUrl() ) ) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 67 * hash + (this.title != null ? this.title.hashCode() : 0);
        hash = 67 * hash + (this.filmUrl != null ? this.filmUrl.hashCode() : 0);
        return hash;
    }

    @Override
    public FilmInfoInterface clone() {
        FilmInfo newInfo = new FilmInfo();
        newInfo.setPoster(new ImageIcon( poster.getImage() ));
        newInfo.setTitle(title);
        newInfo.setGenre(genre);
        newInfo.setFilmUrl(filmUrl);
        newInfo.setPosterUrl(posterUrl);
        newInfo.setYearOfRelease(yearOfRelease);
        newInfo.setLength(length);
        return newInfo;
    }
}

